package com.ansion.commonchat.startup.workmanager.bwork;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wanghongjie on 2023/5/11
 * Describe : 用于定义一次性的后台工作请求，即只需要执行一次的工作任务。
 * 它提供了一种简单的方式来创建和配置后台工作请求
 */
public final class BOneTimeWorkRequest extends BWorkRequest {

    public static @NonNull
    BOneTimeWorkRequest from(
            @NonNull Class<? extends BListenableWorker> workerClass) {
        return new Builder(workerClass).build();
    }

    public static @NonNull
    List<BOneTimeWorkRequest> from(
            @NonNull List<Class<? extends BListenableWorker>> workerClasses) {
        List<BOneTimeWorkRequest> workList = new ArrayList<>(workerClasses.size());
        for (Class<? extends BListenableWorker> workerClass : workerClasses) {
            workList.add(new Builder(workerClass).build());
        }
        return workList;
    }

    BOneTimeWorkRequest(Builder builder) {
        super(builder.mId, builder.mWorkSpec, builder.mTags, builder.mBatchWorkIds, builder.mListener);
    }

    public static final class Builder extends BWorkRequest.Builder<Builder, BOneTimeWorkRequest> {

        public Builder(@NonNull Class<? extends BListenableWorker> workerClass) {
            super(workerClass);
        }

        @Override
        @NonNull
        BOneTimeWorkRequest buildInternal() {
            return new BOneTimeWorkRequest(this);
        }

        @Override
        @NonNull
        Builder getThis() {
            return this;
        }
    }
}